package com.ikun.controller;


import com.ikun.pojo.Address;
import com.ikun.pojo.Result;
import com.ikun.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("address")
public class AddressController {
    @Autowired
    private AddressService addressService;


    @GetMapping("/listAddress/{id}")
    public List<Address> getListAddress(@PathVariable("id") Integer userId) {
        return addressService.getListAddress(userId);
    }

    @GetMapping("/addAddress")
    public Result addAddress(
            @RequestParam("userId") int userId,
            @RequestParam("contactName") String contactName,
            @RequestParam("phoneNumber") String phoneNumber,
            @RequestParam("sex") byte sex, // 注意：byte类型在URL中通常需要特殊处理
            @RequestParam("tag") String tag,
            @RequestParam("deliveryAddress") String deliveryAddress,
            @RequestParam("doorPlate") String doorPlate) {
        try {
            // 这里添加您的业务逻辑，例如保存地址信息到数据库
            // 假设保存成功
            // 通常，您可能需要将这些参数封装到一个对象中，但为了简单起见，这里直接使用参数
             addressService.addUserAddress(userId,contactName,phoneNumber,sex,tag,deliveryAddress,doorPlate);
            return Result.success();
        } catch (Exception e) {
            // 处理异常情况
            return Result.error("error");
        }
    }
}



